import Models from '../src/Models.jsx'
const { message: { error, warning } } = antd;
const { Router, browserHistory } = dva.router;

// Initialize
const app = dva.default({
    history: browserHistory,
    onError(e) {
        const msg = e.message.replace('Error: ', '');
        if(msg.indexOf('请重新登录') !== -1) {
            warning(msg);
        } else {
            error(msg);
        }
    }
});

// Plugins
app.use(require('./utils/DvaLoading.jsx').createLoading());

// 注册models(在webpack.config.js里自动生成Models.jsx文件)
Models.forEach(v => app.model(v));

// 配置路由
app.router(({ history }) => <Router history={history}>{require('./Route.jsx').routes}</Router>);

// Start
app.start('#root');